import pickle

class CheckpointManager:
    def __init__(self, checkpoint_file='checkpoints.pkl'):
        self.checkpoint_file = checkpoint_file
        self.checkpoints = self._load_checkpoints()

    def _load_checkpoints(self):
        try:
            with open(self.checkpoint_file, 'rb') as f:
                return pickle.load(f)
        except FileNotFoundError:
            return {}

    def save_checkpoint(self, node_name, state):
        self.checkpoints[node_name] = state
        with open(self.checkpoint_file, 'wb') as f:
            pickle.dump(self.checkpoints, f)

    def restore_checkpoint(self, node_name):
        return self.checkpoints.get(node_name, None)

class RecoveryManager:
    def __init__(self, dag, checkpoint_manager):
        self.dag = dag
        self.checkpoint_manager = checkpoint_manager

    def recover(self):
        for node_name, node in self.dag.nodes.items():
            state = self.checkpoint_manager.restore_checkpoint(node_name)
            if state:
                node.func.state = state
                print(f"Recovered state for node {node_name}: {state}")